Repository navigation
refactor: keep ETA sampling and estimation together - #60
Merged
stromseng merged 1 commit intoSep 6, 2026
Merged
Conversation
This was referenced Sep 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ETA depends on two pieces of one algorithm that live in unrelated places: task-state code retains the sample window, while renderer formatting computes recent throughput. Changing retention requires knowing how the formatter interprets the first and last retained samples. The formatter also duplicates checks for whether any work remains.
Solution
Put sample retention and remaining-time estimation in
src/progress-estimation.ts:appendProgressSamplekeeps the existing 30-second rolling window, one observation just before that window when available, and the 1,000-sample cap.estimateRemainingMillisowns eligibility checks and throughput calculation, returning a duration orundefined.The estimator accepts a task snapshot directly. It returns no estimate for completed/failed tasks, unknown totals, no remaining work, or insufficient positive time/progress deltas. These are the same conditions previously enforced by the formatter and its helper together.
Examples
Recent throughput
For a running task with 12 total units and 11 processed, retained observations at
(10,000ms, 1)and(40,000ms, 11)represent 10 units over 30 seconds. The remaining unit is estimated at 3,000ms, which the ETA column formats asETA: 00:03.A quiet task crossing the window
Retaining one sample immediately before the rolling window still allows a useful delta when old samples age out. The retention comment and the code that interprets those endpoints now live in the same module.
No available estimate
A task with only its initial observation has no measured throughput.
estimateRemainingMillisreturnsundefined; the standalone ETA remains empty and the combined elapsed/ETA display retains its existing fallback. Unknown totals and terminal task states retain their current output behavior.Validation
bun test: 130 passed, 0 failed, 396 assertions.bun run check: typecheck, lint, formatting, and Knip passed.bun run formatapplied; staged diff whitespace check passed.Existing store tests cover unchanged processed counts, the sample cap, and retention across the rolling window. Existing rendered ETA tests cover estimates, completed tasks, long durations, and sample-based throughput. Non-failing TSGO schema suggestions remain. No build or dev server was run.
Review notes
This layer follows the type/API refactors. Review the two functions in
progress-estimation.ts, then the store import and the smaller formatter. No timing constants, sampling cadence, public schemas, or public exports change, and the new module has no renderer dependency.Stack
GitHub stack #63:
main→ #58 (types) → #59 (execution) → #60 (ETA) → #61 (tests) → #62 (examples). Each PR is based on the layer below it, so its diff contains only that concern. Manage the chain withgh stack; no PR has been merged by this change.